<template>
  <div>
    <el-dialog class="select-prod" title="选择装备详情" :visible.sync="selectDetailVis" @close="close" width="900px" append-to-body :close-on-click-modal='false'>

      <el-row>
        <el-col :span="24">
          <el-table :data="stockProds" border ref="prodInfos" style="width: 100%" @selection-change="selectProd" v-loading="detailLoading">
            <el-table-column type="selection" width="40"></el-table-column>
            <!-- <el-table-column prop="categoryTwoName" label="装备细类"></el-table-column> -->
            <el-table-column prop="prodCode" label="装备编号" width="120"></el-table-column>
            <el-table-column prop="prodName" label="装备名称"></el-table-column>
            <el-table-column prop="rfid" label="RFID编码"></el-table-column>
            <el-table-column prop="prodSpecial" label="规格"></el-table-column>
            <el-table-column prop="emit" label="单位"></el-table-column>
            <el-table-column prop="prodNum" label="库存数"></el-table-column>  
            <el-table-column prop="areaName" label="库区"></el-table-column>
            <el-table-column prop="departmentCode" label="库位"></el-table-column>
          </el-table>
        </el-col>
      </el-row>

        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="close">取 消</el-button>
          <el-button size="small" type="primary" @click="selectprodSuccess()">确 定</el-button>
        </div>
    </el-dialog>

  </div>
</template>

<script>
import { getStore } from '@/utils/app.js';
import { GetStockDetailByStockId } from '@/api/car.js';
export default {
  name: 'selectStockDetailByCar',
  props: ['openselectdetail', 'stockId'],
  data() {
    return {
      selectDetailVis: false,
      detailLoading: false,
      formLabelWidth: '90px',
      selectedProd: [],
      stockProds: [],
       // 分页
        pageNum: 1,
        pageSize: 8,
        total_num: null,
    }
  },
  computed: {
    storeid() {
      return this.$store.state.store.store_id || getStore();
    },
    main_store() {
      return this.$store.state.store.main_store;
    },
  },
  mounted() {
    this.$store.commit('ware/SET_SELECTPROD', []);
    
  },
  methods: {
    close() {
      this.selectDetailVis = false;
      this.$emit("update:openselectdetail", false);
    //   this.$store.commit('ware/SET_STOCKDETAIL', []);
    },
    // 选择商品
    selectProd(val) {
      this.selectedProd = val;
    },
    selectprodSuccess() {
      this.$store.commit('ware/SET_STOCKDETAIL', this.selectedProd);
      this.selectDetailVis = false;
      this.$emit("update:openselectdetail", false);
    //   this.$refs.prodInfos.clearSelection()
    },
  },
  watch: {
    openselectdetail(newVal,oldVal) {  
      this.selectDetailVis = newVal;
    },
    stockId(newVal) {
        if (newVal) {
            this.detailLoading = true;
            GetStockDetailByStockId({ stockId: this.stockId }).then( res => {
                this.stockProds = res.data.data;
                this.detailLoading = false;
            })
        }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/config.scss';

  .label-wrap {
    &.category { @include labelwrap(left,50,40); }
    &.date {
      @include labelwrap(center,50,40); }
    &.keyword { @include labelwrap(right,110,40); }
  }
  .autospace {
    height: 30px;
  }
  
</style>